package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.FireControlBean;
import com.zkca.xf.model.javabean.uploadbean.Dianliu_requ;
import com.zkca.xf.model.javabean.uploadbean.RequestPage;
import com.zkca.xf.view.FireAlarmLView;
import com.zkca.xf.view.FireControlView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/8/20.
 */

public class FireControl_LPresenter extends BasePresenter {

    private FireAlarmLView fireControlView;
    private DataManager dataManager;
    public FireControl_LPresenter(LifecycleProvider<ActivityEvent> provider, FireAlarmLView  fireControlView) {
        super(provider);
        this.fireControlView=fireControlView;
        dataManager=DataManager.getInstance();
    }


    public void getShuan(RequestPage requestPage){
        fireControlView.showProgressDialog();

        dataManager.getShuan(requestPage)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<String>bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribe(new DefaultObserver<String>() {
                    @Override
                    public void onNext(String fireControlBean) {
                        fireControlView.getFireAlarm(fireControlBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fireControlView.hideProgressDialog();
                        fireControlView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        fireControlView.hideProgressDialog();
                    }
                });
    }
}
